home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / cweb31p9d.lha / CWeb / common.c < prev    next >
C/C++ Source or Header  |  1994-07-08  |  37KB  |  1,930 lines

  1. /*1:*/
  2. #line 57 "common.w"
  3.  
  4. #line 161 "common.ch"
  5. /*5:*/
  6. #line 101 "common.w"
  7.  
  8. #include <ctype.h>
  9.  
  10. /*:5*//*8:*/
  11. #line 163 "common.w"
  12.  
  13. #include <stdio.h>
  14.  
  15. /*:8*//*22:*/
  16. #line 428 "common.ch"
  17.  
  18. #include <stdlib.h> 
  19. #include <stddef.h> 
  20.  
  21. #ifdef _AMIGA
  22. #define PATH_SEPARATOR   ','
  23. #define DIR_SEPARATOR    '/'
  24. #define DEVICE_SEPARATOR ':'
  25. #else
  26. #ifdef __TURBOC__
  27. #define PATH_SEPARATOR   ';'
  28. #define DIR_SEPARATOR    '\\'
  29. #define DEVICE_SEPARATOR ':'
  30. #else
  31. #define PATH_SEPARATOR   ':'
  32. #define DIR_SEPARATOR    '/'
  33. #define DEVICE_SEPARATOR '/'
  34. #endif
  35. #endif
  36. #line 470 "common.w"
  37.  
  38. /*:22*//*81:*/
  39. #line 1384 "common.ch"
  40.  
  41. #include <string.h>
  42.  
  43. /*:81*//*87:*/
  44. #line 1455 "common.ch"
  45.  
  46. #ifdef __TURBOC__
  47. #include <alloc.h> 
  48. #include <io.h> 
  49. #endif
  50.  
  51.  
  52. /*:87*//*89:*/
  53. #line 1481 "common.ch"
  54.  
  55. #ifdef _AMIGA
  56. #include <libraries/locale.h>
  57. #include <proto/locale.h>
  58. #include <proto/exec.h>
  59.  
  60. struct Library*LocaleBase;
  61. struct Catalog*catalog;
  62. int i;
  63. #else 
  64. typedef long int LONG;
  65. typedef char*STRPTR;
  66. #define EXEC_TYPES_H 1 
  67. #endif
  68.  
  69. #define STRINGARRAY 1 
  70. #define get_string(n) AppStrings[n].as_Str 
  71.  
  72. #include "cweb.h"
  73.  
  74. /*:89*//*92:*/
  75. #line 1541 "common.ch"
  76.  
  77. #ifdef _AMIGA
  78. #include <exec/types.h>
  79. #include <libraries/dos.h>
  80. #include <clib/alib_protos.h>
  81. #include <clib/exec_protos.h>
  82. #include <clib/dos_protos.h>
  83. #include <pragmas/exec_pragmas.h>
  84. #include <pragmas/dos_pragmas.h>
  85.  
  86. #include <string.h>
  87. #include <dos.h>
  88.  
  89. #include <rexx/rxslib.h>
  90. #include <rexx/errors.h>
  91. #endif
  92.  
  93. /*:92*/
  94. #line 161 "common.ch"
  95.  
  96. /*88:*/
  97. #line 1462 "common.ch"
  98.  
  99. #ifdef __TURBOC__
  100. #define HUGE huge
  101. #else
  102. #define HUGE
  103. #endif
  104.  
  105.  
  106. /*:88*/
  107. #line 162 "common.ch"
  108.  
  109. #line 59 "common.w"
  110. #define ctangle 0
  111. #define cweave 1 \
  112.  
  113. #define and_and 04
  114. #define lt_lt 020
  115. #define gt_gt 021
  116. #define plus_plus 013
  117. #define minus_minus 01
  118. #define minus_gt 031
  119. #define not_eq 032
  120. #define lt_eq 034
  121. #define gt_eq 035
  122. #define eq_eq 036
  123. #define or_or 037
  124. #define dot_dot_dot 016
  125. #define colon_colon 06
  126. #define period_ast 026
  127. #define minus_gt_ast 027 \
  128.  
  129. #define buf_size 100
  130. #define long_buf_size 500
  131. #define xisspace(c) (isspace(c) &&((unsigned char) c<0200) ) 
  132. #define xisupper(c) (isupper(c) &&((unsigned char) c<0200) )  \
  133.  
  134. #define max_include_depth 10 \
  135.  \
  136.  
  137. #define max_file_name_length 256 \
  138.  
  139. #define cur_file file[include_depth]
  140. #define cur_file_name file_name[include_depth]
  141. #define cur_line line[include_depth]
  142. #define web_file file[0]
  143. #define web_file_name file_name[0] \
  144.  
  145. #define lines_dont_match (change_limit-change_buffer!=limit-buffer|| \
  146. strncmp(buffer,change_buffer,(size_t) (limit-buffer) ) )  \
  147.  
  148. #define if_section_start_make_pending(b) {*limit= '!'; \
  149. for(loc= buffer;xisspace(*loc) ;loc++) ; \
  150. *limit= ' '; \
  151. if(*loc=='@'&&(xisspace(*(loc+1) ) ||*(loc+1) =='*') ) change_pending= b; \
  152. } \
  153.  
  154. #define max_sections 2000 \
  155.  \
  156.  
  157. #define too_long() {include_depth--; \
  158. err_print(get_string(MSG_ERROR_CO22) ) ;goto restart;} \
  159.  
  160. #define max_bytes 90000 \
  161.  
  162. #define max_names 4000 \
  163.  \
  164.  
  165. #define length(c) (size_t) ((c+1) ->byte_start-(c) ->byte_start)  \
  166.  
  167. #define print_id(c) term_write((c) ->byte_start,length((c) ) )  \
  168.  
  169. #define alloc_object(object,size,type)  \
  170. if(!(object= (type*) calloc(size,sizeof(type) ) ) )  \
  171. fatal("",get_string(MSG_FATAL_CO85) ) ; \
  172.  
  173. #define hash_size 353 \
  174.  
  175. #define llink link
  176. #define rlink dummy.Rlink
  177. #define root name_dir->rlink \
  178.  \
  179.  
  180. #define first_chunk(p) ((p) ->byte_start+2) 
  181. #define prefix_length(p) (int) ((unsigned char) *((p) ->byte_start) *256+ \
  182. (unsigned char) *((p) ->byte_start+1) ) 
  183. #define set_prefix_length(p,m) (*((p) ->byte_start) = (m) /256, \
  184. *((p) ->byte_start+1) = (m) %256)  \
  185.  
  186. #define less 0
  187. #define equal 1
  188. #define greater 2
  189. #define prefix 3
  190. #define extension 4 \
  191.  
  192. #define bad_extension 5 \
  193.  \
  194.  
  195. #define spotless 0
  196. #define harmless_message 1
  197. #define error_message 2
  198. #define fatal_message 3
  199. #define mark_harmless {if(history==spotless) history= harmless_message;}
  200. #define mark_error history= error_message \
  201.  
  202. #define RETURN_OK 0
  203. #define RETURN_WARN 5
  204. #define RETURN_ERROR 10
  205. #define RETURN_FAIL 20 \
  206.  
  207. #define confusion(s) fatal(get_string(MSG_FATAL_CO66) ,s)  \
  208.  \
  209.  
  210. #define show_banner flags['b']
  211. #define show_progress flags['p']
  212. #define show_stats flags['s']
  213. #define show_happiness flags['h']
  214. #define use_amiga_keywords flags['a']
  215. #define use_german_macros flags['g']
  216. #define indent_param_decl flags['i']
  217. #define send_error_messages flags['m']
  218. #define order_decl_stmt flags['o'] \
  219.  
  220. #define update_terminal fflush(stdout)  \
  221.  
  222. #define new_line putchar('\n') 
  223. #define putxchar putchar
  224. #define term_write(a,b) fflush(stdout) ,fwrite(a,sizeof(char) ,b,stdout) 
  225. #define C_printf(c,a) fprintf(C_file,c,a) 
  226. #define C_putc(c) putc(c,C_file)  \
  227.  \
  228.  
  229. #define max_path_length 4095 \
  230.  
  231.  
  232. #line 59 "common.w"
  233.  
  234. /*2:*/
  235. #line 72 "common.w"
  236.  
  237. typedef short boolean;
  238. boolean program;
  239.  
  240. /*:2*//*7:*/
  241. #line 157 "common.w"
  242.  
  243. #line 197 "common.ch"
  244. char*buffer;
  245. char*buffer_end;
  246. char*limit;
  247. char*loc;
  248. #line 162 "common.w"
  249.  
  250. /*:7*//*10:*/
  251. #line 212 "common.w"
  252.  
  253. int include_depth;
  254. #line 236 "common.ch"
  255. FILE**file;
  256. FILE*change_file;
  257. char**file_name;
  258. char*change_file_name;
  259. char*alt_web_file_name;
  260. int*line;
  261. #line 221 "common.w"
  262. int change_line;
  263. int change_depth;
  264. boolean input_has_ended;
  265. boolean changing;
  266. boolean web_file_open= 0;
  267.  
  268. /*:10*//*20:*/
  269. #line 416 "common.w"
  270.  
  271. #line 360 "common.ch"
  272. typedef unsigned char eight_bits;
  273. typedef unsigned short sixteen_bits;
  274. #line 418 "common.w"
  275. sixteen_bits section_count;
  276. #line 368 "common.ch"
  277. boolean*changed_section;
  278. #line 420 "common.w"
  279. boolean change_pending;
  280.  
  281. boolean print_where= 0;
  282.  
  283. /*:20*//*27:*/
  284. #line 586 "common.w"
  285.  
  286. typedef struct name_info{
  287. #line 549 "common.ch"
  288. char HUGE*byte_start;
  289. #line 589 "common.w"
  290. /*31:*/
  291. #line 623 "common.w"
  292.  
  293. #line 622 "common.ch"
  294. struct name_info HUGE*link;
  295. #line 625 "common.w"
  296.  
  297. /*:31*//*40:*/
  298. #line 722 "common.w"
  299.  
  300. union{
  301. #line 702 "common.ch"
  302. struct name_info HUGE*Rlink;
  303.  
  304. #line 726 "common.w"
  305. char Ilk;
  306. }dummy;
  307.  
  308. /*:40*//*55:*/
  309. #line 990 "common.ch"
  310.  
  311. #line 991 "common.ch"
  312. void HUGE*equiv_or_xref;
  313. #line 1056 "common.w"
  314.  
  315. /*:55*/
  316. #line 589 "common.w"
  317.  
  318. }name_info;
  319. #line 560 "common.ch"
  320. typedef name_info HUGE*name_pointer;
  321. char HUGE*byte_mem;
  322. char HUGE*byte_mem_end;
  323. name_info HUGE*name_dir;
  324. name_pointer name_dir_end;
  325. #line 596 "common.w"
  326.  
  327. /*:27*//*29:*/
  328. #line 609 "common.w"
  329.  
  330. name_pointer name_ptr;
  331. #line 578 "common.ch"
  332. char HUGE*byte_ptr;
  333. #line 612 "common.w"
  334.  
  335. #line 586 "common.ch"
  336. /*:29*//*32:*/
  337. #line 636 "common.w"
  338.  
  339. typedef name_pointer*hash_pointer;
  340. #line 630 "common.ch"
  341. name_pointer*hash;
  342. hash_pointer hash_end;
  343. #line 640 "common.w"
  344. hash_pointer h;
  345.  
  346. #line 639 "common.ch"
  347. /*:32*//*56:*/
  348. #line 1074 "common.w"
  349.  
  350. int history= spotless;
  351.  
  352. /*:56*//*67:*/
  353. #line 1212 "common.w"
  354.  
  355. int argc;
  356. char**argv;
  357. #line 1229 "common.ch"
  358. char*C_file_name;
  359. char*tex_file_name;
  360. char*idx_file_name;
  361. char*scn_file_name;
  362. boolean flags[256];
  363. #line 1220 "common.w"
  364.  
  365. /*:67*//*77:*/
  366. #line 1366 "common.w"
  367.  
  368. FILE*C_file;
  369. FILE*tex_file;
  370. FILE*idx_file;
  371. FILE*scn_file;
  372. FILE*active_file;
  373.  
  374. /*:77*/
  375. #line 60 "common.w"
  376.  
  377. /*3:*/
  378. #line 82 "common.w"
  379. int phase;
  380.  
  381. /*:3*//*11:*/
  382. #line 238 "common.w"
  383.  
  384. #line 257 "common.ch"
  385. char*change_buffer;
  386. #line 240 "common.w"
  387. char*change_limit;
  388.  
  389. /*:11*//*83:*/
  390. #line 1415 "common.ch"
  391.  
  392. char*include_path;
  393. char*p,*path_prefix,*next_path_prefix;
  394.  
  395. /*:83*//*93:*/
  396. #line 1563 "common.ch"
  397.  
  398. #ifdef _AMIGA
  399. extern struct ExecBase*SysBase;
  400. extern struct DOSBase*DOSBase;
  401.  
  402. STRPTR CreateArgstring(STRPTR,long);
  403. void DeleteArgstring(STRPTR);
  404. struct RexxMsg*CreateRexxMsg(struct MsgPort*,STRPTR,STRPTR);
  405. void DeleteRexxMsg(struct RexxMsg*);
  406.  
  407. long result= 20;
  408. char msg_string[BUFSIZ];
  409. char pth_buffer[BUFSIZ];
  410. char cur_buffer[BUFSIZ];
  411.  
  412. struct RexxMsg*rm;
  413. struct MsgPort*rp;
  414.  
  415. #pragma libcall RexxSysBase CreateArgstring 7e 0802
  416. #pragma libcall RexxSysBase DeleteArgstring 84 801
  417. #pragma libcall RexxSysBase CreateRexxMsg   90 09803
  418. #pragma libcall RexxSysBase DeleteRexxMsg   96 801
  419.  
  420. #define MSGPORT  "SC_SCMSG"
  421. #define PORTNAME "CWEBPORT"
  422. #define RXEXTENS "rexx"
  423.  
  424. struct RxsLib*RexxSysBase= NULL;
  425. #endif
  426.  
  427. /*:93*/
  428. #line 61 "common.w"
  429.  
  430. /*33:*/
  431. #line 639 "common.ch"
  432.  
  433. extern int names_match(name_pointer,char*,int,eight_bits);
  434. #line 644 "common.w"
  435.  
  436. /*:33*//*38:*/
  437. #line 685 "common.ch"
  438.  
  439. #line 686 "common.ch"
  440. extern void init_p(name_pointer,eight_bits);
  441. #line 697 "common.w"
  442.  
  443. /*:38*//*46:*/
  444. #line 798 "common.ch"
  445.  
  446. #line 799 "common.ch"
  447. extern void init_node(name_pointer);
  448. #line 846 "common.w"
  449.  
  450. /*:46*//*53:*/
  451. #line 942 "common.ch"
  452.  
  453. static int section_name_cmp(char**,int,name_pointer);
  454. #line 1011 "common.w"
  455.  
  456. /*:53*//*57:*/
  457. #line 1003 "common.ch"
  458.  
  459. #line 1004 "common.ch"
  460. extern void err_print(char*);
  461. #line 1086 "common.w"
  462.  
  463. /*:57*//*60:*/
  464. #line 1045 "common.ch"
  465.  
  466. #line 1046 "common.ch"
  467. extern int wrap_up(void);
  468. extern void print_stats(void);
  469. #line 1135 "common.w"
  470.  
  471. #line 1068 "common.ch"
  472. /*:60*//*63:*/
  473. #line 1139 "common.ch"
  474.  
  475. #line 1140 "common.ch"
  476. extern void fatal(char*,char*);
  477. extern void overflow(char*);
  478. #line 1167 "common.w"
  479.  
  480. /*:63*//*69:*/
  481. #line 1265 "common.ch"
  482.  
  483. #line 1266 "common.ch"
  484. static void scan_args(void);
  485. #line 1245 "common.w"
  486.  
  487. /*:69*//*85:*/
  488. #line 1437 "common.ch"
  489.  
  490. #ifdef __TURBOC__
  491. extern void far*allocsafe(unsigned long,unsigned long);
  492. #endif
  493.  
  494.  
  495. /*:85*//*96:*/
  496. #line 1684 "common.ch"
  497.  
  498. #ifdef _AMIGA
  499. static int PutRexxMsg(struct MsgPort*,long,STRPTR,struct RexxMsg*);
  500. int __stdargs call_rexx(char*,long*);
  501. #endif
  502.  
  503. /*:96*//*102:*/
  504. #line 1795 "common.ch"
  505.  
  506. int get_line(void);
  507. name_pointer add_section_name(name_pointer,int,char*,char*,int);
  508. name_pointer id_lookup(char*,char*,char);
  509. name_pointer section_lookup(char*,char*,int);
  510. void check_complete(void);
  511. void common_init(void);
  512. void extend_section_name(name_pointer,char*,char*,int);
  513. void print_prefix_name(name_pointer);
  514. void print_section_name(name_pointer);
  515. void reset_input(void);
  516. void sprint_section_name(char*,name_pointer);
  517.  
  518. /*:102*//*103:*/
  519. #line 1810 "common.ch"
  520.  
  521. static boolean set_path(char*,char*);
  522. static int input_ln(FILE*);
  523. static int web_strcmp(char HUGE*,int,char HUGE*,int);
  524. static void check_change(void);
  525. static void prime_the_change_buffer(void);
  526.  
  527. /*:103*/
  528. #line 62 "common.w"
  529.  
  530.  
  531. /*:1*//*4:*/
  532. #line 88 "common.w"
  533.  
  534. #line 175 "common.ch"
  535. void common_init(void)
  536. {
  537. /*30:*/
  538. #line 592 "common.ch"
  539.  
  540. alloc_object(buffer,long_buf_size,char);
  541. buffer_end= buffer+buf_size-2;
  542. limit= loc= buffer;
  543. alloc_object(file,max_include_depth,FILE*);
  544. alloc_object(file_name,max_include_depth,char*);
  545. for(phase= 0;phase<max_include_depth;phase++)
  546. alloc_object(file_name[phase],max_file_name_length,char);
  547. alloc_object(change_file_name,max_file_name_length,char);
  548. alloc_object(alt_web_file_name,max_file_name_length,char);
  549. alloc_object(line,max_include_depth,int);
  550. alloc_object(change_buffer,buf_size,char);
  551. alloc_object(changed_section,max_sections,boolean);
  552. #ifdef __TURBOC__
  553. byte_mem= allocsafe(max_bytes,sizeof(*byte_mem));
  554. name_dir= allocsafe(max_names,sizeof(*name_dir));
  555. #else
  556. alloc_object(byte_mem,max_bytes,char);
  557. alloc_object(name_dir,max_names,name_info);
  558. #endif
  559. byte_mem_end= byte_mem+max_bytes-1;
  560. name_dir_end= name_dir+max_names-1;
  561. name_dir->byte_start= byte_ptr= byte_mem;
  562.  
  563. #line 615 "common.w"
  564. name_ptr= name_dir+1;
  565. name_ptr->byte_start= byte_mem;
  566.  
  567. /*:30*//*34:*/
  568. #line 648 "common.ch"
  569.  
  570. #line 649 "common.ch"
  571. alloc_object(hash,hash_size,name_pointer);
  572. hash_end= hash+hash_size-1;
  573. for(h= hash;h<=hash_end;*h++= NULL);
  574. alloc_object(C_file_name,max_file_name_length,char);
  575. alloc_object(tex_file_name,max_file_name_length,char);
  576. alloc_object(idx_file_name,max_file_name_length,char);
  577. alloc_object(scn_file_name,max_file_name_length,char);
  578. #line 649 "common.w"
  579.  
  580. /*:34*//*41:*/
  581. #line 729 "common.w"
  582.  
  583. root= NULL;
  584.  
  585. /*:41*//*84:*/
  586. #line 1419 "common.ch"
  587.  
  588. alloc_object(include_path,max_path_length+1,char);
  589. strcpy(include_path,CWEBINPUTS);
  590.  
  591. /*:84*/
  592. #line 177 "common.ch"
  593. ;
  594. /*90:*/
  595. #line 1506 "common.ch"
  596.  
  597. #ifdef _AMIGA
  598. if(LocaleBase= OpenLibrary("locale.library",38L)){
  599. if(catalog= OpenCatalog(NULL,"cweb.catalog",
  600. OC_BuiltInLanguage,"english",TAG_DONE)){
  601. for(i= MSG_ERROR_CO9;i<=MSG_STATS_CW248_6;++i)
  602. AppStrings[i].as_Str= GetCatalogStr(catalog,i,AppStrings[i].as_Str);
  603. }
  604. }
  605. #endif
  606.  
  607. /*:90*/
  608. #line 178 "common.ch"
  609. ;
  610. /*68:*/
  611. #line 1241 "common.ch"
  612.  
  613. #line 1242 "common.ch"
  614. show_banner= show_happiness= show_progress= 1;
  615. #ifdef _AMIGA
  616. use_amiga_keywords= 
  617. #endif
  618. use_german_macros= indent_param_decl= order_decl_stmt= 1;
  619.  
  620. #line 1227 "common.w"
  621.  
  622. /*:68*/
  623. #line 179 "common.ch"
  624. ;
  625. /*78:*/
  626. #line 1373 "common.w"
  627.  
  628. scan_args();
  629. if(program==ctangle){
  630. if((C_file= fopen(C_file_name,"w"))==NULL)
  631. #line 1352 "common.ch"
  632. fatal(get_string(MSG_FATAL_CO78),C_file_name);
  633. #line 1378 "common.w"
  634.  
  635. }
  636. else{
  637. if((tex_file= fopen(tex_file_name,"w"))==NULL)
  638. #line 1359 "common.ch"
  639. fatal(get_string(MSG_FATAL_CO78),tex_file_name);
  640. #line 1383 "common.w"
  641. }
  642.  
  643. /*:78*/
  644. #line 180 "common.ch"
  645. ;
  646. }
  647. #line 96 "common.w"
  648.  
  649. /*:4*//*9:*/
  650. #line 170 "common.w"
  651.  
  652. #line 208 "common.ch"
  653. static int input_ln(FILE*fp)
  654.  
  655. #line 173 "common.w"
  656. {
  657. register int c= EOF;
  658. register char*k;
  659. if(feof(fp))return(0);
  660. limit= k= buffer;
  661. while(k<=buffer_end&&(c= getc(fp))!=EOF&&c!='\n')
  662. if((*(k++)= c)!=' ')limit= k;
  663. if(k>buffer_end)
  664. if((c= getc(fp))!=EOF&&c!='\n'){
  665. #line 216 "common.ch"
  666. ungetc(c,fp);loc= buffer;err_print(get_string(MSG_ERROR_CO9));
  667. #line 183 "common.w"
  668.  
  669. }
  670. if(c==EOF&&limit==buffer)return(0);
  671.  
  672. return(1);
  673. }
  674.  
  675. /*:9*//*12:*/
  676. #line 249 "common.w"
  677.  
  678. #line 265 "common.ch"
  679. static void prime_the_change_buffer(void)
  680. #line 252 "common.w"
  681. {
  682. change_limit= change_buffer;
  683. /*13:*/
  684. #line 263 "common.w"
  685.  
  686. while(1){
  687. change_line++;
  688. if(!input_ln(change_file))return;
  689. if(limit<buffer+2)continue;
  690. if(buffer[0]!='@')continue;
  691. if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]);
  692. if(buffer[1]=='x')break;
  693. if(buffer[1]=='y'||buffer[1]=='z'||buffer[1]=='i'){
  694. loc= buffer+2;
  695. #line 272 "common.ch"
  696. err_print(get_string(MSG_ERROR_CO13));
  697. #line 274 "common.w"
  698.  
  699. }
  700. }
  701.  
  702. /*:13*/
  703. #line 254 "common.w"
  704. ;
  705. /*14:*/
  706. #line 280 "common.w"
  707.  
  708. do{
  709. change_line++;
  710. if(!input_ln(change_file)){
  711. #line 279 "common.ch"
  712. err_print(get_string(MSG_ERROR_CO14));
  713. #line 285 "common.w"
  714.  
  715. return;
  716. }
  717. }while(limit==buffer);
  718.  
  719. /*:14*/
  720. #line 255 "common.w"
  721. ;
  722. /*15:*/
  723. #line 290 "common.w"
  724.  
  725. {
  726. #line 287 "common.ch"
  727. change_limit= change_buffer+(ptrdiff_t)(limit-buffer);
  728. strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
  729. #line 294 "common.w"
  730. }
  731.  
  732. /*:15*/
  733. #line 256 "common.w"
  734. ;
  735. }
  736.  
  737. /*:12*//*16:*/
  738. #line 318 "common.w"
  739.  
  740. #line 296 "common.ch"
  741. static void check_change(void)
  742. #line 321 "common.w"
  743. {
  744. int n= 0;
  745. if(lines_dont_match)return;
  746. change_pending= 0;
  747. if(!changed_section[section_count]){
  748. if_section_start_make_pending(1);
  749. if(!change_pending)changed_section[section_count]= 1;
  750. }
  751. while(1){
  752. changing= 1;print_where= 1;change_line++;
  753. if(!input_ln(change_file)){
  754. #line 303 "common.ch"
  755. err_print(get_string(MSG_ERROR_CO16_1));
  756. #line 333 "common.w"
  757.  
  758. change_limit= change_buffer;changing= 0;
  759. return;
  760. }
  761. if(limit>buffer+1&&buffer[0]=='@'){
  762. if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]);
  763. /*17:*/
  764. #line 356 "common.w"
  765.  
  766. if(buffer[1]=='x'||buffer[1]=='z'){
  767. #line 317 "common.ch"
  768. loc= buffer+2;err_print(get_string(MSG_ERROR_CO17_1));
  769. #line 359 "common.w"
  770.  
  771. }
  772. else if(buffer[1]=='y'){
  773. if(n>0){
  774. loc= buffer+2;
  775. printf("\n! Hmm... %d ",n);
  776. #line 324 "common.ch"
  777. err_print(get_string(MSG_ERROR_CO17_2));
  778. #line 366 "common.w"
  779.  
  780. }
  781. change_depth= include_depth;
  782. return;
  783. }
  784.  
  785. /*:17*/
  786. #line 340 "common.w"
  787. ;
  788. }
  789. /*15:*/
  790. #line 290 "common.w"
  791.  
  792. {
  793. #line 287 "common.ch"
  794. change_limit= change_buffer+(ptrdiff_t)(limit-buffer);
  795. strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
  796. #line 294 "common.w"
  797. }
  798.  
  799. /*:15*/
  800. #line 342 "common.w"
  801. ;
  802. changing= 0;cur_line++;
  803. while(!input_ln(cur_file)){
  804. if(include_depth==0){
  805. #line 310 "common.ch"
  806. err_print(get_string(MSG_ERROR_CO16_2));
  807. #line 347 "common.w"
  808.  
  809. input_has_ended= 1;return;
  810. }
  811. include_depth--;cur_line++;
  812. }
  813. if(lines_dont_match)n++;
  814. }
  815. }
  816.  
  817. /*:16*//*18:*/
  818. #line 376 "common.w"
  819.  
  820. #line 332 "common.ch"
  821. void reset_input(void)
  822. #line 379 "common.w"
  823. {
  824. limit= buffer;loc= buffer+1;buffer[0]= ' ';
  825. /*19:*/
  826. #line 391 "common.w"
  827.  
  828. if((web_file= fopen(web_file_name,"r"))==NULL){
  829. strcpy(web_file_name,alt_web_file_name);
  830. if((web_file= fopen(web_file_name,"r"))==NULL)
  831. #line 339 "common.ch"
  832. fatal(get_string(MSG_FATAL_CO19_1),web_file_name);
  833. #line 396 "common.w"
  834. }
  835.  
  836.  
  837. web_file_open= 1;
  838. #line 351 "common.ch"
  839. /*97:*/
  840. #line 1705 "common.ch"
  841.  
  842. #ifdef _AMIGA
  843. if(send_error_messages){
  844. Forbid();
  845. if((rp= FindPort(MSGPORT))!=NULL);
  846. Permit();
  847.  
  848. if(!rp){
  849. strcpy(msg_string,"run <nil: >nil: scmsg ");
  850. strcat(msg_string,getenv("SCMSGOPT"));
  851. system(msg_string);
  852. }
  853.  
  854. if(GetCurrentDirName(cur_buffer,BUFSIZ)&&
  855. AddPart(cur_buffer,web_file_name,BUFSIZ)){
  856. sprintf(msg_string,"newbld \"%s\"",cur_buffer);
  857. call_rexx(msg_string,&result);
  858. }
  859. }
  860. #endif
  861.  
  862. /*:97*/
  863. #line 351 "common.ch"
  864.  
  865. if((change_file= fopen(change_file_name,"r"))==NULL)
  866. fatal(get_string(MSG_FATAL_CO19_2),change_file_name);
  867. #line 402 "common.w"
  868.  
  869. /*:19*/
  870. #line 381 "common.w"
  871. ;
  872. include_depth= 0;cur_line= 0;change_line= 0;
  873. change_depth= include_depth;
  874. changing= 1;prime_the_change_buffer();changing= !changing;
  875. limit= buffer;loc= buffer+1;buffer[0]= ' ';input_has_ended= 0;
  876. }
  877.  
  878. /*:18*//*21:*/
  879. #line 424 "common.w"
  880.  
  881. #line 375 "common.ch"
  882. int get_line(void)
  883. #line 426 "common.w"
  884. {
  885. restart:
  886. if(changing&&include_depth==change_depth)
  887. /*25:*/
  888. #line 529 "common.w"
  889. {
  890. change_line++;
  891. if(!input_ln(change_file)){
  892. #line 514 "common.ch"
  893. err_print(get_string(MSG_ERROR_CO25_1));
  894. #line 533 "common.w"
  895.  
  896. buffer[0]= '@';buffer[1]= 'z';limit= buffer+2;
  897. }
  898. if(limit>buffer){
  899. if(change_pending){
  900. if_section_start_make_pending(0);
  901. if(change_pending){
  902. changed_section[section_count]= 1;change_pending= 0;
  903. }
  904. }
  905. *limit= ' ';
  906. if(buffer[0]=='@'){
  907. if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]);
  908. if(buffer[1]=='x'||buffer[1]=='y'){
  909. loc= buffer+2;
  910. #line 521 "common.ch"
  911. err_print(get_string(MSG_ERROR_CO25_2));
  912. #line 549 "common.w"
  913.  
  914. }
  915. else if(buffer[1]=='z'){
  916. prime_the_change_buffer();changing= !changing;print_where= 1;
  917. }
  918. }
  919. }
  920. }
  921.  
  922. /*:25*/
  923. #line 429 "common.w"
  924. ;
  925. if(!changing||include_depth>change_depth){
  926. /*24:*/
  927. #line 512 "common.w"
  928. {
  929. cur_line++;
  930. while(!input_ln(cur_file)){
  931. print_where= 1;
  932. if(include_depth==0){input_has_ended= 1;break;}
  933. else{
  934. fclose(cur_file);include_depth--;
  935. if(changing&&include_depth==change_depth)break;
  936. cur_line++;
  937. }
  938. }
  939. if(!changing&&!input_has_ended)
  940. if(limit-buffer==change_limit-change_buffer)
  941. if(buffer[0]==change_buffer[0])
  942. if(change_limit>change_buffer)check_change();
  943. }
  944.  
  945. /*:24*/
  946. #line 431 "common.w"
  947. ;
  948. if(changing&&include_depth==change_depth)goto restart;
  949. }
  950. loc= buffer;*limit= ' ';
  951. if(*buffer=='@'&&(*(buffer+1)=='i'||*(buffer+1)=='I')){
  952. loc= buffer+2;
  953. while(loc<=limit&&(*loc==' '||*loc=='\t'||*loc=='"'))loc++;
  954. if(loc>=limit){
  955. #line 382 "common.ch"
  956. err_print(get_string(MSG_ERROR_CO21_1));
  957. #line 440 "common.w"
  958.  
  959. goto restart;
  960. }
  961. if(include_depth>=max_include_depth-1){
  962. #line 389 "common.ch"
  963. err_print(get_string(MSG_ERROR_CO21_2));
  964. #line 445 "common.w"
  965.  
  966. goto restart;
  967. }
  968. include_depth++;
  969. /*23:*/
  970. #line 471 "common.w"
  971. {
  972. char temp_file_name[max_file_name_length];
  973. char*cur_file_name_end= cur_file_name+max_file_name_length-1;
  974. char*k= cur_file_name,*kk;
  975. int l;
  976.  
  977. while(*loc!=' '&&*loc!='\t'&&*loc!='"'&&k<=cur_file_name_end)*k++= *loc++;
  978. if(k>cur_file_name_end)too_long();
  979.  
  980. *k= '\0';
  981. if((cur_file= fopen(cur_file_name,"r"))!=NULL){
  982. cur_line= 0;print_where= 1;
  983. goto restart;
  984. }
  985. #line 480 "common.ch"
  986. if(0==set_path(include_path,getenv("CWEBINPUTS"))){
  987. include_depth--;goto restart;
  988. }
  989. path_prefix= include_path;
  990. while(path_prefix){
  991. for(kk= temp_file_name,p= path_prefix,l= 0;
  992. p&&*p&&*p!=PATH_SEPARATOR;
  993. *kk++= *p++,l++);
  994. if(path_prefix&&*path_prefix&&*path_prefix!=PATH_SEPARATOR&&
  995. *--p!=DEVICE_SEPARATOR&&*p!=DIR_SEPARATOR){
  996. *kk++= DIR_SEPARATOR;l++;
  997. }
  998. if(k+l+2>=cur_file_name_end)too_long();
  999. strcpy(kk,cur_file_name);
  1000. if(cur_file= fopen(temp_file_name,"r")){
  1001. cur_line= 0;print_where= 1;goto restart;
  1002. }
  1003. if(next_path_prefix= strchr(path_prefix,PATH_SEPARATOR))
  1004. path_prefix= next_path_prefix+1;
  1005. else break;
  1006. }
  1007. #line 507 "common.ch"
  1008. include_depth--;err_print(get_string(MSG_ERROR_CO23));goto restart;
  1009. #line 510 "common.w"
  1010. }
  1011.  
  1012. /*:23*/
  1013. #line 449 "common.w"
  1014. ;
  1015. }
  1016. return(!input_has_ended);
  1017. }
  1018.  
  1019. #line 412 "common.ch"
  1020. /*:21*//*26:*/
  1021. #line 561 "common.w"
  1022.  
  1023. #line 532 "common.ch"
  1024. void check_complete(void){
  1025. if(change_limit!=change_buffer){
  1026. strncpy(buffer,change_buffer,(size_t)(change_limit-change_buffer+1));
  1027. limit= buffer+(ptrdiff_t)(change_limit-change_buffer);
  1028. #line 567 "common.w"
  1029. changing= 1;change_depth= include_depth;loc= buffer;
  1030. #line 542 "common.ch"
  1031. err_print(get_string(MSG_ERROR_CO26));
  1032. #line 569 "common.w"
  1033.  
  1034. }
  1035. }
  1036.  
  1037. /*:26*//*35:*/
  1038. #line 652 "common.w"
  1039.  
  1040. #line 666 "common.ch"
  1041. name_pointer id_lookup(char*first,char*last,char t)
  1042.  
  1043.  
  1044.  
  1045.  
  1046. #line 658 "common.w"
  1047. {
  1048. char*i= first;
  1049. int h;
  1050. int l;
  1051. name_pointer p;
  1052. if(last==NULL)for(last= first;*last!='\0';last++);
  1053. #line 677 "common.ch"
  1054. l= (int)(last-first);
  1055. #line 665 "common.w"
  1056. /*36:*/
  1057. #line 675 "common.w"
  1058.  
  1059. h= (unsigned char)*i;
  1060. while(++i<last)h= (h+h+(int)((unsigned char)*i))%hash_size;
  1061.  
  1062.  
  1063. /*:36*/
  1064. #line 665 "common.w"
  1065. ;
  1066. /*37:*/
  1067. #line 683 "common.w"
  1068.  
  1069. p= hash[h];
  1070. while(p&&!names_match(p,first,l,t))p= p->link;
  1071. if(p==NULL){
  1072. p= name_ptr;
  1073. p->link= hash[h];hash[h]= p;
  1074. }
  1075.  
  1076. /*:37*/
  1077. #line 666 "common.w"
  1078. ;
  1079. if(p==name_ptr)/*39:*/
  1080. #line 698 "common.w"
  1081. {
  1082. #line 694 "common.ch"
  1083. if(byte_ptr+l>byte_mem_end)overflow(get_string(MSG_OVERFLOW_CO39_1));
  1084. if(name_ptr>=name_dir_end)overflow(get_string(MSG_OVERFLOW_CO39_2));
  1085. #line 701 "common.w"
  1086. strncpy(byte_ptr,first,l);
  1087. (++name_ptr)->byte_start= byte_ptr+= l;
  1088. if(program==cweave)init_p(p,t);
  1089. }
  1090.  
  1091. /*:39*/
  1092. #line 667 "common.w"
  1093. ;
  1094. return(p);
  1095. }
  1096.  
  1097. /*:35*//*42:*/
  1098. #line 756 "common.w"
  1099.  
  1100. #line 711 "common.ch"
  1101. void print_section_name(name_pointer p)
  1102. #line 760 "common.w"
  1103. {
  1104. #line 718 "common.ch"
  1105. char HUGE*ss;
  1106. char HUGE*s= first_chunk(p);
  1107. #line 762 "common.w"
  1108. name_pointer q= p+1;
  1109. while(p!=name_dir){
  1110. ss= (p+1)->byte_start-1;
  1111. if(*ss==' '&&ss>=s){
  1112. #line 728 "common.ch"
  1113. term_write(s,(size_t)(ss-s));p= q->link;q= p;
  1114. }else{
  1115. term_write(s,(size_t)(ss+1-s));p= name_dir;q= NULL;
  1116. #line 769 "common.w"
  1117. }
  1118. s= p->byte_start;
  1119. }
  1120. if(q)term_write("...",3);
  1121. }
  1122.  
  1123. /*:42*//*43:*/
  1124. #line 775 "common.w"
  1125.  
  1126. #line 740 "common.ch"
  1127. void sprint_section_name(char*dest,name_pointer p)
  1128. #line 780 "common.w"
  1129. {
  1130. #line 747 "common.ch"
  1131. char HUGE*ss;
  1132. char HUGE*s= first_chunk(p);
  1133. #line 782 "common.w"
  1134. name_pointer q= p+1;
  1135. while(p!=name_dir){
  1136. ss= (p+1)->byte_start-1;
  1137. if(*ss==' '&&ss>=s){
  1138. p= q->link;q= p;
  1139. }else{
  1140. ss++;p= name_dir;
  1141. }
  1142. #line 755 "common.ch"
  1143. strncpy(dest,s,(size_t)(ss-s)),dest+= ss-s;
  1144. #line 791 "common.w"
  1145. s= p->byte_start;
  1146. }
  1147. *dest= '\0';
  1148. }
  1149.  
  1150. /*:43*//*44:*/
  1151. #line 796 "common.w"
  1152.  
  1153. #line 764 "common.ch"
  1154. void print_prefix_name(name_pointer p)
  1155. #line 800 "common.w"
  1156. {
  1157. #line 771 "common.ch"
  1158. char HUGE*s= first_chunk(p);
  1159. #line 802 "common.w"
  1160. int l= prefix_length(p);
  1161. term_write(s,l);
  1162. if(s+l<(p+1)->byte_start)term_write("...",3);
  1163. }
  1164.  
  1165. /*:44*//*45:*/
  1166. #line 817 "common.w"
  1167.  
  1168. #line 782 "common.ch"
  1169. static int web_strcmp(char HUGE*j,int j_len,char HUGE*k,int k_len)
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175. {
  1176. char HUGE*j1= j+j_len;
  1177. char HUGE*k1= k+k_len;
  1178. #line 823 "common.w"
  1179. while(k<k1&&j<j1&&*j==*k)k++,j++;
  1180. if(k==k1)if(j==j1)return equal;
  1181. else return extension;
  1182. else if(j==j1)return prefix;
  1183. else if(*j<*k)return less;
  1184. else return greater;
  1185. }
  1186.  
  1187. /*:45*//*47:*/
  1188. #line 847 "common.w"
  1189.  
  1190. #line 812 "common.ch"
  1191. name_pointer add_section_name(name_pointer par,int c,
  1192. char*first,char*last,int ispref)
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199. #line 855 "common.w"
  1200. {
  1201. name_pointer p= name_ptr;
  1202. #line 829 "common.ch"
  1203. char HUGE*s= first_chunk(p);
  1204. int name_len= (int)(last-first)+ispref;
  1205. if(s+name_len>byte_mem_end)overflow(get_string(MSG_OVERFLOW_CO39_1));
  1206. if(name_ptr+1>=name_dir_end)overflow(get_string(MSG_OVERFLOW_CO39_2));
  1207. #line 861 "common.w"
  1208. (++name_ptr)->byte_start= byte_ptr= s+name_len;
  1209. if(ispref){
  1210. *(byte_ptr-1)= ' ';
  1211. name_len--;
  1212. name_ptr->link= name_dir;
  1213. (++name_ptr)->byte_start= byte_ptr;
  1214. }
  1215. set_prefix_length(p,name_len);
  1216. strncpy(s,first,name_len);
  1217. p->llink= NULL;
  1218. p->rlink= NULL;
  1219. init_node(p);
  1220. return par==NULL?(root= p):c==less?(par->llink= p):(par->rlink= p);
  1221. }
  1222.  
  1223. /*:47*//*48:*/
  1224. #line 876 "common.w"
  1225.  
  1226. #line 844 "common.ch"
  1227. void extend_section_name(name_pointer p,char*first,char*last,int ispref)
  1228.  
  1229.  
  1230.  
  1231.  
  1232. #line 883 "common.w"
  1233. {
  1234. #line 858 "common.ch"
  1235. char HUGE*s;
  1236. name_pointer q= p+1;
  1237. int name_len= (int)(last-first)+ispref;
  1238. if(name_ptr>=name_dir_end)overflow(get_string(MSG_OVERFLOW_CO39_2));
  1239. #line 888 "common.w"
  1240. while(q->link!=name_dir)q= q->link;
  1241. q->link= name_ptr;
  1242. s= name_ptr->byte_start;
  1243. name_ptr->link= name_dir;
  1244. #line 868 "common.ch"
  1245. if(s+name_len>byte_mem_end)overflow(get_string(MSG_OVERFLOW_CO39_1));
  1246. #line 893 "common.w"
  1247. (++name_ptr)->byte_start= byte_ptr= s+name_len;
  1248. strncpy(s,first,name_len);
  1249. if(ispref)*(byte_ptr-1)= ' ';
  1250. }
  1251.  
  1252. /*:48*//*49:*/
  1253. #line 904 "common.w"
  1254.  
  1255. #line 884 "common.ch"
  1256. name_pointer section_lookup(char*first,char*last,int ispref)
  1257.  
  1258.  
  1259.  
  1260. #line 909 "common.w"
  1261. {
  1262. int c= 0;
  1263. name_pointer p= root;
  1264. name_pointer q= NULL;
  1265. name_pointer r= NULL;
  1266. name_pointer par= NULL;
  1267.  
  1268. #line 894 "common.ch"
  1269. int name_len= (int)(last-first)+1;
  1270. #line 917 "common.w"
  1271. /*50:*/
  1272. #line 928 "common.w"
  1273.  
  1274. while(p){
  1275. c= web_strcmp(first,name_len,first_chunk(p),prefix_length(p));
  1276. if(c==less||c==greater){
  1277. if(r==NULL)
  1278. par= p;
  1279. p= (c==less?p->llink:p->rlink);
  1280. }else{
  1281. if(r!=NULL){
  1282. #line 904 "common.ch"
  1283. printf(get_string(MSG_ERROR_CO50_1));
  1284.  
  1285. print_prefix_name(p);
  1286. printf(get_string(MSG_ERROR_CO50_2));
  1287. #line 941 "common.w"
  1288. print_prefix_name(r);
  1289. err_print(">");
  1290. return name_dir;
  1291. }
  1292. r= p;
  1293. p= p->llink;
  1294. q= r->rlink;
  1295. }
  1296. if(p==NULL)
  1297. p= q,q= NULL;
  1298. }
  1299.  
  1300. /*:50*/
  1301. #line 918 "common.w"
  1302. ;
  1303. /*51:*/
  1304. #line 953 "common.w"
  1305.  
  1306. if(r==NULL)
  1307. return add_section_name(par,c,first,last+1,ispref);
  1308.  
  1309. /*:51*/
  1310. #line 919 "common.w"
  1311. ;
  1312. /*52:*/
  1313. #line 961 "common.w"
  1314.  
  1315. switch(section_name_cmp(&first,name_len,r)){
  1316.  
  1317. case prefix:
  1318. if(!ispref){
  1319. #line 914 "common.ch"
  1320. printf(get_string(MSG_ERROR_CO52_1));
  1321. #line 967 "common.w"
  1322.  
  1323. print_section_name(r);
  1324. err_print(">");
  1325. }
  1326. else if(name_len<prefix_length(r))set_prefix_length(r,name_len);
  1327.  
  1328. case equal:return r;
  1329. case extension:if(!ispref||first<=last)
  1330. extend_section_name(r,first,last+1,ispref);
  1331. return r;
  1332. case bad_extension:
  1333. #line 921 "common.ch"
  1334. printf(get_string(MSG_ERROR_CO52_2));
  1335. #line 979 "common.w"
  1336.  
  1337. print_section_name(r);
  1338. err_print(">");
  1339. return r;
  1340. default:
  1341. #line 931 "common.ch"
  1342. printf(get_string(MSG_ERROR_CO52_3));
  1343.  
  1344. print_prefix_name(r);
  1345. printf(get_string(MSG_ERROR_CO52_4));
  1346. #line 988 "common.w"
  1347. print_section_name(r);
  1348. err_print(">");
  1349. return r;
  1350. }
  1351.  
  1352. /*:52*/
  1353. #line 920 "common.w"
  1354. ;
  1355. }
  1356.  
  1357. /*:49*//*54:*/
  1358. #line 1012 "common.w"
  1359.  
  1360. #line 953 "common.ch"
  1361. static int section_name_cmp(char**pfirst,int len,name_pointer r)
  1362.  
  1363.  
  1364.  
  1365. #line 1017 "common.w"
  1366. {
  1367. char*first= *pfirst;
  1368. name_pointer q= r+1;
  1369. #line 963 "common.ch"
  1370. char HUGE*ss;
  1371. char HUGE*s= first_chunk(r);
  1372. #line 1021 "common.w"
  1373. int c;
  1374. int ispref;
  1375. while(1){
  1376. ss= (r+1)->byte_start-1;
  1377. if(*ss==' '&&ss>=r->byte_start)ispref= 1,q= q->link;
  1378. else ispref= 0,ss++,q= name_dir;
  1379. switch(c= web_strcmp(first,len,s,ss-s)){
  1380. case equal:if(q==name_dir)
  1381. if(ispref){
  1382. #line 971 "common.ch"
  1383. *pfirst= first+(ptrdiff_t)(ss-s);
  1384. #line 1031 "common.w"
  1385. return extension;
  1386. }else return equal;
  1387. else return(q->byte_start==(q+1)->byte_start)?equal:prefix;
  1388. case extension:
  1389. if(!ispref)return bad_extension;
  1390. first+= ss-s;
  1391. #line 978 "common.ch"
  1392. if(q!=name_dir){len-= (int)(ss-s);s= q->byte_start;r= q;continue;}
  1393. #line 1038 "common.w"
  1394. *pfirst= first;return extension;
  1395. default:return c;
  1396. }
  1397. }
  1398. }
  1399.  
  1400. /*:54*//*58:*/
  1401. #line 1087 "common.w"
  1402.  
  1403. #line 1013 "common.ch"
  1404. void err_print(char*s)
  1405. #line 1091 "common.w"
  1406. {
  1407. char*k,*l;
  1408. printf(*s=='!'?"\n%s":"%s",s);
  1409. if(web_file_open)/*59:*/
  1410. #line 1107 "common.w"
  1411.  
  1412. #line 1023 "common.ch"
  1413. {if(changing&&include_depth==change_depth){
  1414. printf(get_string(MSG_ERROR_CO59_1),change_line);
  1415. /*98:*/
  1416. #line 1736 "common.ch"
  1417.  
  1418. #ifdef _AMIGA
  1419. if(send_error_messages){
  1420. if(GetCurrentDirName(cur_buffer,BUFSIZ)&&
  1421. AddPart(cur_buffer,web_file_name,BUFSIZ)&&
  1422. GetCurrentDirName(pth_buffer,BUFSIZ)&&
  1423. AddPart(pth_buffer,change_file_name,BUFSIZ))
  1424. sprintf(msg_string,"newmsg \"%s\" \"%s\" %d 0 \"\" 0 Error 997 %s",
  1425. cur_buffer,pth_buffer,change_line,s);
  1426. }
  1427. #endif
  1428.  
  1429. /*:98*/
  1430. #line 1025 "common.ch"
  1431.  
  1432. }
  1433. else if(include_depth==0){
  1434. printf(get_string(MSG_ERROR_CO59_2),cur_line);
  1435. /*99:*/
  1436. #line 1752 "common.ch"
  1437.  
  1438. #ifdef _AMIGA
  1439. if(send_error_messages){
  1440. if(GetCurrentDirName(cur_buffer,BUFSIZ)&&
  1441. AddPart(cur_buffer,cur_file_name,BUFSIZ))
  1442. sprintf(msg_string,"newmsg \"%s\" \"%s\" %d 0 \"\" 0 Error 998 %s",
  1443. cur_buffer,cur_buffer,cur_line,s);
  1444. }
  1445. #endif
  1446.  
  1447. /*:99*/
  1448. #line 1029 "common.ch"
  1449.  
  1450. }
  1451. else{
  1452. printf(get_string(MSG_ERROR_CO59_3),cur_line,cur_file_name);
  1453. /*100:*/
  1454. #line 1767 "common.ch"
  1455.  
  1456. #ifdef _AMIGA
  1457. if(send_error_messages){
  1458. strcpy(msg_string,"\0");
  1459. if(GetCurrentDirName(cur_buffer,BUFSIZ)&&
  1460. AddPart(cur_buffer,cur_file_name,BUFSIZ)&&
  1461. GetCurrentDirName(pth_buffer,BUFSIZ)&&
  1462. AddPart(pth_buffer,web_file_name,BUFSIZ))
  1463. sprintf(msg_string,"newmsg \"%s\" \"%s\" %d 0 \"\" 0 Error 999 %s",
  1464. pth_buffer,cur_buffer,cur_line,s);
  1465. }
  1466. #endif
  1467.  
  1468. /*:100*/
  1469. #line 1033 "common.ch"
  1470.  
  1471. }
  1472.  
  1473. /*101:*/
  1474. #line 1785 "common.ch"
  1475.  
  1476. #ifdef _AMIGA
  1477. if(send_error_messages&&msg_string)
  1478. call_rexx(msg_string,&result);
  1479. #endif
  1480.  
  1481. /*:101*/
  1482. #line 1036 "common.ch"
  1483.  
  1484. #line 1112 "common.w"
  1485. l= (loc>=limit?limit:loc);
  1486. if(l>buffer){
  1487. for(k= buffer;k<l;k++)
  1488. if(*k=='\t')putchar(' ');
  1489. else putchar(*k);
  1490. putchar('\n');
  1491. for(k= buffer;k<l;k++)putchar(' ');
  1492. }
  1493. for(k= l;k<limit;k++)putchar(*k);
  1494. if(*limit=='|')putchar('|');
  1495. putchar(' ');
  1496. }
  1497.  
  1498. /*:59*/
  1499. #line 1094 "common.w"
  1500. ;
  1501. update_terminal;mark_error;
  1502. }
  1503.  
  1504. /*:58*//*61:*/
  1505. #line 1082 "common.ch"
  1506.  
  1507. #ifndef __TURBOC__
  1508. int wrap_up(void){
  1509. putchar('\n');
  1510. if(show_stats)print_stats();
  1511. /*62:*/
  1512. #line 1152 "common.w"
  1513.  
  1514. switch(history){
  1515. #line 1124 "common.ch"
  1516. case spotless:
  1517. if(show_happiness)printf(get_string(MSG_HAPPINESS_CO62));break;
  1518. case harmless_message:
  1519. printf(get_string(MSG_WARNING_CO62));break;
  1520. case error_message:
  1521. printf(get_string(MSG_ERROR_CO62));break;
  1522. case fatal_message:
  1523. printf(get_string(MSG_FATAL_CO62));
  1524. #line 1160 "common.w"
  1525. }
  1526.  
  1527. /*:62*/
  1528. #line 1087 "common.ch"
  1529. ;
  1530. /*91:*/
  1531. #line 1521 "common.ch"
  1532.  
  1533. #ifdef _AMIGA
  1534. if(LocaleBase){
  1535. CloseCatalog(catalog);
  1536. CloseLibrary(LocaleBase);
  1537. }
  1538. #endif
  1539.  
  1540. /*:91*/
  1541. #line 1088 "common.ch"
  1542. ;
  1543. switch(history){
  1544. case harmless_message:return(RETURN_WARN);break;
  1545. case error_message:return(RETURN_ERROR);break;
  1546. case fatal_message:return(RETURN_FAIL);break;
  1547. default:return(RETURN_OK);
  1548. }
  1549. }
  1550. #else
  1551. int wrap_up(void){
  1552. int return_val;
  1553.  
  1554. putchar('\n');
  1555. if(show_stats)print_stats();
  1556. /*62:*/
  1557. #line 1152 "common.w"
  1558.  
  1559. switch(history){
  1560. #line 1124 "common.ch"
  1561. case spotless:
  1562. if(show_happiness)printf(get_string(MSG_HAPPINESS_CO62));break;
  1563. case harmless_message:
  1564. printf(get_string(MSG_WARNING_CO62));break;
  1565. case error_message:
  1566. printf(get_string(MSG_ERROR_CO62));break;
  1567. case fatal_message:
  1568. printf(get_string(MSG_FATAL_CO62));
  1569. #line 1160 "common.w"
  1570. }
  1571.  
  1572. /*:62*/
  1573. #line 1102 "common.ch"
  1574. ;
  1575. /*91:*/
  1576. #line 1521 "common.ch"
  1577.  
  1578. #ifdef _AMIGA
  1579. if(LocaleBase){
  1580. CloseCatalog(catalog);
  1581. CloseLibrary(LocaleBase);
  1582. }
  1583. #endif
  1584.  
  1585. /*:91*/
  1586. #line 1103 "common.ch"
  1587. ;
  1588. switch(history){
  1589. case harmless_message:return_val= RETURN_WARN;break;
  1590. case error_message:return_val= RETURN_ERROR;break;
  1591. case fatal_message:return_val= RETURN_FAIL;break;
  1592. default:return_val= RETURN_OK;
  1593. }
  1594. return(return_val);
  1595. }
  1596. #endif
  1597. #line 1151 "common.w"
  1598.  
  1599. /*:61*//*64:*/
  1600. #line 1150 "common.ch"
  1601. void fatal(char*s,char*t)
  1602. #line 1174 "common.w"
  1603. {
  1604. if(*s)printf(s);
  1605. err_print(t);
  1606. history= fatal_message;exit(wrap_up());
  1607. }
  1608.  
  1609. /*:64*//*65:*/
  1610. #line 1159 "common.ch"
  1611. void overflow(char*t)
  1612. #line 1185 "common.w"
  1613. {
  1614. #line 1166 "common.ch"
  1615. printf(get_string(MSG_FATAL_CO65),t);fatal("","");
  1616. #line 1187 "common.w"
  1617. }
  1618.  
  1619.  
  1620. /*:65*//*70:*/
  1621. #line 1246 "common.w"
  1622.  
  1623. #line 1274 "common.ch"
  1624. static void scan_args(void)
  1625. #line 1249 "common.w"
  1626. {
  1627. char*dot_pos;
  1628. char*name_pos;
  1629. register char*s;
  1630. boolean found_web= 0,found_change= 0,found_out= 0;
  1631.  
  1632. boolean flag_change;
  1633.  
  1634. while(--argc>0){
  1635. if((**(++argv)=='-'||**argv=='+')&&*(*argv+1))/*74:*/
  1636. #line 1340 "common.w"
  1637.  
  1638. {
  1639. if(**argv=='-')flag_change= 0;
  1640. else flag_change= 1;
  1641. for(dot_pos= *argv+1;*dot_pos>'\0';dot_pos++)
  1642. flags[*dot_pos]= flag_change;
  1643. }
  1644.  
  1645. /*:74*/
  1646. #line 1258 "common.w"
  1647.  
  1648. else{
  1649. s= name_pos= *argv;dot_pos= NULL;
  1650. #line 1285 "common.ch"
  1651. while(*s){
  1652. if(*s=='.')dot_pos= s++;
  1653. #ifdef _AMIGA
  1654. else if((*s==DIR_SEPARATOR)||(*s==DEVICE_SEPARATOR))dot_pos= NULL,name_pos= ++s;
  1655. #else
  1656. else if(*s==DIR_SEPARATOR)dot_pos= NULL,name_pos= ++s;
  1657. #endif
  1658. else s++;
  1659. }
  1660.  
  1661. #line 1266 "common.w"
  1662. if(!found_web)/*71:*/
  1663. #line 1284 "common.w"
  1664.  
  1665. {
  1666. if(s-*argv>max_file_name_length-5)
  1667. /*76:*/
  1668. #line 1345 "common.ch"
  1669. fatal(get_string(MSG_FATAL_CO76),*argv);
  1670. #line 1361 "common.w"
  1671.  
  1672.  
  1673. /*:76*/
  1674. #line 1287 "common.w"
  1675. ;
  1676. if(dot_pos==NULL)
  1677. sprintf(web_file_name,"%s.w",*argv);
  1678. else{
  1679. strcpy(web_file_name,*argv);
  1680. *dot_pos= 0;
  1681. }
  1682. sprintf(alt_web_file_name,"%s.web",*argv);
  1683. sprintf(tex_file_name,"%s.tex",name_pos);
  1684. sprintf(idx_file_name,"%s.idx",name_pos);
  1685. sprintf(scn_file_name,"%s.scn",name_pos);
  1686. sprintf(C_file_name,"%s.c",name_pos);
  1687. found_web= 1;
  1688. }
  1689.  
  1690. /*:71*/
  1691. #line 1267 "common.w"
  1692.  
  1693. else if(!found_change)/*72:*/
  1694. #line 1302 "common.w"
  1695.  
  1696. {
  1697. if(strcmp(*argv,"-")==0)found_change= -1;
  1698. else{
  1699. if(s-*argv>max_file_name_length-4)
  1700. /*76:*/
  1701. #line 1345 "common.ch"
  1702. fatal(get_string(MSG_FATAL_CO76),*argv);
  1703. #line 1361 "common.w"
  1704.  
  1705.  
  1706. /*:76*/
  1707. #line 1307 "common.w"
  1708. ;
  1709. if(dot_pos==NULL)
  1710. sprintf(change_file_name,"%s.ch",*argv);
  1711. else strcpy(change_file_name,*argv);
  1712. found_change= 1;
  1713. }
  1714. }
  1715.  
  1716. /*:72*/
  1717. #line 1268 "common.w"
  1718.  
  1719. else if(!found_out)/*73:*/
  1720. #line 1315 "common.w"
  1721.  
  1722. {
  1723. if(s-*argv>max_file_name_length-5)
  1724. /*76:*/
  1725. #line 1345 "common.ch"
  1726. fatal(get_string(MSG_FATAL_CO76),*argv);
  1727. #line 1361 "common.w"
  1728.  
  1729.  
  1730. /*:76*/
  1731. #line 1318 "common.w"
  1732. ;
  1733. if(dot_pos==NULL){
  1734. sprintf(tex_file_name,"%s.tex",*argv);
  1735. sprintf(idx_file_name,"%s.idx",*argv);
  1736. sprintf(scn_file_name,"%s.scn",*argv);
  1737. sprintf(C_file_name,"%s.c",*argv);
  1738. }else{
  1739. strcpy(tex_file_name,*argv);
  1740. if(flags['x']){
  1741. if(program==cweave&&strcmp(*argv+strlen(*argv)-4,".tex")!=0)
  1742. #line 1317 "common.ch"
  1743. fatal(get_string(MSG_FATAL_CO73),*argv);
  1744. #line 1329 "common.w"
  1745.  
  1746. strcpy(idx_file_name,*argv);
  1747. strcpy(idx_file_name+strlen(*argv)-4,".idx");
  1748. strcpy(scn_file_name,*argv);
  1749. strcpy(scn_file_name+strlen(*argv)-4,".scn");
  1750. }
  1751. strcpy(C_file_name,*argv);
  1752. }
  1753. found_out= 1;
  1754. }
  1755.  
  1756. /*:73*/
  1757. #line 1269 "common.w"
  1758.  
  1759. else/*75:*/
  1760. #line 1348 "common.w"
  1761.  
  1762. {
  1763. if(program==ctangle)
  1764. #line 1331 "common.ch"
  1765. fatal(get_string(MSG_FATAL_CO75_1),"");
  1766.  
  1767. #ifdef _AMIGA
  1768. else fatal(get_string(MSG_FATAL_CO75_2),"");
  1769. #else
  1770. else fatal(get_string(MSG_FATAL_CO75_3),"");
  1771. #endif
  1772.  
  1773. #line 1358 "common.w"
  1774. }
  1775.  
  1776. #line 1345 "common.ch"
  1777. /*:75*/
  1778. #line 1270 "common.w"
  1779. ;
  1780. }
  1781. }
  1782. if(!found_web)/*75:*/
  1783. #line 1348 "common.w"
  1784.  
  1785. {
  1786. if(program==ctangle)
  1787. #line 1331 "common.ch"
  1788. fatal(get_string(MSG_FATAL_CO75_1),"");
  1789.  
  1790. #ifdef _AMIGA
  1791. else fatal(get_string(MSG_FATAL_CO75_2),"");
  1792. #else
  1793. else fatal(get_string(MSG_FATAL_CO75_3),"");
  1794. #endif
  1795.  
  1796. #line 1358 "common.w"
  1797. }
  1798.  
  1799. #line 1345 "common.ch"
  1800. /*:75*/
  1801. #line 1273 "common.w"
  1802. ;
  1803. #line 1301 "common.ch"
  1804. #if defined( _AMIGA )
  1805. if(found_change<=0)strcpy(change_file_name,"NIL:");
  1806. #else
  1807. #if defined( __TURBOC__ )
  1808. if(found_change<=0)strcpy(change_file_name,"nul");
  1809. #else
  1810. if(found_change<=0)strcpy(change_file_name,"/dev/null");
  1811. #endif
  1812. #endif
  1813.  
  1814. #line 1275 "common.w"
  1815. }
  1816.  
  1817. /*:70*//*82:*/
  1818. #line 1394 "common.ch"
  1819.  
  1820. static boolean set_path(char*ptr,char*override)
  1821. {
  1822. if(override){
  1823. if(strlen(override)>=max_path_length){
  1824. err_print("! Include path too long");return(0);
  1825.  
  1826. }
  1827. else strcpy(ptr,override);
  1828. }
  1829. return(1);
  1830. }
  1831.  
  1832. /*:82*//*86:*/
  1833. #line 1443 "common.ch"
  1834.  
  1835. #ifdef __TURBOC__
  1836. void far*allocsafe(unsigned long nunits,unsigned long unitsz)
  1837. {
  1838. void far*p= farcalloc(nunits,unitsz);
  1839. if(p==NULL)fatal("",get_string(MSG_FATAL_CO85));
  1840.  
  1841. return p;
  1842. }
  1843. #endif
  1844.  
  1845.  
  1846. /*:86*//*94:*/
  1847. #line 1597 "common.ch"
  1848.  
  1849. #ifdef _AMIGA
  1850. static int PutRexxMsg(struct MsgPort*mp,long action,STRPTR arg0,
  1851. struct RexxMsg*arg1)
  1852. {
  1853. if((rm= CreateRexxMsg(mp,RXEXTENS,mp->mp_Node.ln_Name))!=NULL){
  1854. rm->rm_Action= action;
  1855. rm->rm_Args[0]= arg0;
  1856. rm->rm_Args[1]= (STRPTR)arg1;
  1857.  
  1858. Forbid();
  1859. if((rp= FindPort(MSGPORT))!=NULL)
  1860. PutMsg(rp,(struct Message*)rm);
  1861. Permit();
  1862.  
  1863. if(rp==NULL)
  1864. DeleteRexxMsg(rm);
  1865. }
  1866. return(rm!=NULL&&rp!=NULL);
  1867. }
  1868. #endif
  1869.  
  1870. /*:94*//*95:*/
  1871. #line 1624 "common.ch"
  1872.  
  1873. #ifdef _AMIGA
  1874. int __stdargs call_rexx(char*str,long*result)
  1875. {
  1876. char*arg;
  1877. struct MsgPort*mp;
  1878. struct RexxMsg*rm,*rm2;
  1879. int ret= FALSE;
  1880. int pend;
  1881.  
  1882. if(!(RexxSysBase= (struct RxsLib*)OpenLibrary(RXSNAME,0)))
  1883. return(ret);
  1884.  
  1885. Forbid();
  1886. if(FindPort(PORTNAME)==NULL)
  1887. mp= CreatePort(PORTNAME,0);
  1888. Permit();
  1889.  
  1890. if(mp!=NULL){
  1891. if((arg= CreateArgstring(str,strlen(str)))!=NULL){
  1892. if(PutRexxMsg(mp,RXCOMM|RXFF_STRING,arg,NULL)){
  1893.  
  1894. for(pend= 1;pend!=0;)
  1895. if(WaitPort(mp)!=NULL)
  1896. while((rm= (struct RexxMsg*)GetMsg(mp))!=NULL)
  1897. if(rm->rm_Node.mn_Node.ln_Type==NT_REPLYMSG){
  1898. ret= TRUE;
  1899. *result= rm->rm_Result1;
  1900. if((rm2= (struct RexxMsg*)rm->rm_Args[1])!=NULL){
  1901. rm2->rm_Result1= rm->rm_Result1;
  1902. rm2->rm_Result2= 0;
  1903. ReplyMsg((struct Message*)rm2);
  1904. }
  1905. DeleteRexxMsg(rm);
  1906. pend--;
  1907. }
  1908. else{
  1909. rm->rm_Result2= 0;
  1910. if(PutRexxMsg(mp,rm->rm_Action,rm->rm_Args[0],rm))
  1911. pend++;
  1912. else{
  1913. rm->rm_Result1= RC_FATAL;
  1914. ReplyMsg((struct Message*)rm);
  1915. }
  1916. }
  1917. }
  1918. DeleteArgstring(arg);
  1919. }
  1920. DeletePort(mp);
  1921. }
  1922.  
  1923. CloseLibrary((struct Library*)RexxSysBase);
  1924.  
  1925. return(ret);
  1926. }
  1927. #endif
  1928.  
  1929. /*:95*/
  1930.